1. Field of the Invention
The present invention relates to the field of computer programming, and more particularly to a system, method, and computer-readable code for combining a meta data file and Java source code to dynamically create Java classes and JavaBeans. This technique enables creating objects and JavaBeans in a new, more flexible manner.
2. Description of the Related Art
Java is an object-oriented programming language. As with programs written in other object-oriented languages, Java programs operate by instantiating objects and invoking methods upon these objects. xe2x80x9cJavaBeansxe2x80x9d is the name of a component architecture for use with the Java programming language. (xe2x80x9cJavaBeansxe2x80x9d and xe2x80x9cJavaxe2x80x9d are trademarks of Sun Microsystems, Inc.) A JavaBean is the Java term for a xe2x80x9ccomponentxe2x80x9d, where a component is a reusable building block of application logic that a programmer can combine with other components to form an application program.
A Java programmer creates a Java application program by writing new code and assembling existing components (i.e. JavaBeans), to provide the desired functionality for his application. A JavaBean may contain code for a relatively simple function such as displaying a button on a graphical user interface (xe2x80x9cGUIxe2x80x9d), but it may also contain quite complex code. JavaBeans are intended to execute locally, within the Java Virtual Machine (xe2x80x9cJVMxe2x80x9d) on which a Java application is running.
To create an object in the current art, the Java programmer specifies code that invokes a constructor method that is called, by convention, xe2x80x9cnewxe2x80x9d. This method may be defined in the class for which an object is to be instantiated, or in a superclass from which this class inherits in the object hierarchy. The constructor method defines functionality that is to be performed when constructing, or instantiating, a new object. The constructor method may optionally use parameters, which will be used to specify initialization values, known as xe2x80x9cinstance dataxe2x80x9d, for the newly-created object.
However, the current art requires a static, predefined specification of the objects to be created, where this predefined specification includes the values that are to be used for initializing the instance data parameters. The code instantiating an object is coded directly into the source code of a Java program. The parameter values may be specified in the source code, or they may be obtained at run-time. For the latter case, the values may be read from a file, obtained from a user by prompting, or passed as invocation parameters.
It may happen that there is a need to create a large number of objects, either in a single class or in different classes. Further, there may be a need to enable an end-user of an application to specify the objects, and/or the instance data values, to be used by the application. There is currently no convenient way to handle these situations. The current art requires statically specifying the creation of each object in the Java source code. In addition, the end-user will likely be unable to change the source code (either due to lack of Java programming skills, or code locking techniques which prevent changing the code base, or both) to modify the objects and/or instance data specified in the program.
Accordingly, what is needed is a technique whereby the objects to be created during execution of a Java program can be dynamically specified, and whereby the values to be used for instantiating these objects can also be dynamically specified.
An object of the present invention is to provide a technique for more easily and efficiently creating objects for use in the Java programming language.
Another object of the present invention is to provide this technique such that it enables more easily and efficiently creating JavaBeans.
A further object of the present invention is to provide this technique by combining a meta data file and Java source code to dynamically create Java classes and JavaBeans.
Yet another object of the present invention is to provide this technique in a manner that defines all instance data for a particular object in a separate file from the Java source code.
Still another object of the invention is to provide this technique in a manner that isolates all Java source code for a particular application in a separate file from the instance data used to create objects for that application.
A further object of the present invention is to provide a technique whereby an end-user can conveniently specify creation of objects and/or values to be used for instance data of created objects.
Other objects and advantages of the present invention will be set forth in part in the description and in the drawings which follow and, in part, will be obvious from the description or may be learned by practice of the invention.
To achieve the foregoing objects, and in accordance with the purpose of the invention as broadly described herein, the present invention provides a system, method, and computer-readable code for combining a meta data file and an object-oriented source code input file to create an object-oriented source code output file that will be used to dynamically create objects at compile time in a computing environment. In one aspect, this technique comprises: creating a meta data file, wherein the meta data file includes specifications for one or more macros, each of the macro specifications comprising: a name for a particular macro, wherein the same name may be specified in one or more of the macro specifications; and values for one or more parameters for the particular macro; creating an object-oriented source code input file, wherein the input file comprises a plurality of lines, and wherein each of the lines may be characterized as a normal object-oriented source code statement or as a line within a scope of a macro reference; copying each of the normal object-oriented source code statements to an object-oriented source code output file; and processing each of the lines within the scope of the macro reference. The processing further comprises: locating one or more matching macro specifications in the meta data file, wherein the name of the matching macro specification is identical to a reference name used in the macro reference; expanding the lines within the scope of the macro reference using the one or more located specifications; and writing the expanded lines to the output file. Preferably, the processing of each of the lines further comprises: detecting an opening macro reference, the opening macro reference specifying the reference name, and wherein the detected opening reference begins the scope of the macro reference; detecting a closing macro reference, wherein the detected closing reference ends the scope of the macro reference; and wherein the detected opening and closing macro references are not themselves expanded.
In one embodiment, the expanding preferably further comprises: parsing each of the lines within the scope of the macro reference; copying each of the parsed lines which does not contain a macro parameter reference to the output file; and expanding the parsed line using the located macro specification when the parsed line contains one or more of the macro parameter references. Expanding the parsed line preferably further comprises: retrieving a corresponding one of the parameter values from the located macro specification using a sequence number from the macro parameter reference; and substituting the retrieved parameter value for the macro parameter reference, wherein the retrieving and the substituting are repeated for each of the one or more macro parameter references in the parsed line.
In another embodiment, the expanding preferably further comprises: parsing each of the lines within the scope of the macro reference; detecting an opening conditional macro processing statement in the parsed line; evaluating the detected opening conditional macro processing statement; bypassing one or more lines within the scope of said macro reference until detecting an ending conditional macro processing statement when the evaluating has a negative result; and expanding one or more lines of the input file when the evaluating has a positive result, until detecting said ending conditional macro processing statement. Preferably, the evaluating has a positive result when a condition on the opening conditional macro processing statement evaluates to a Boolean value xe2x80x9cTruexe2x80x9d, and the evaluating further comprises: locating a string value in the condition; retrieving a corresponding condition value from the located macro specification using a conditional parameter sequence number from the condition; and comparing the retrieved corresponding value to the string value. The expanding preferably further comprises: parsing each of the lines within the scope of the macro reference; copying each of the parsed lines which does not contain a macro parameter reference to the output file; and expanding the parsed line using the located macro specification when the parsed line contains one or more of the macro parameter references. Expanding the parsed line preferably further comprises: retrieving a corresponding one of the parameter values from the matching macro specification using a sequence number from the macro parameter reference; and substituting the retrieved parameter value for the macro parameter reference, wherein the retrieving and the substituting are repeated for each of the one or more macro parameter references in the parsed line.
The object-oriented source code input file and the object-oriented source code output file may use the Java programming language.
In a further aspect, the present invention provides a technique for combining a meta data file and Java source code file to dynamically create Java classes and JavaBeans. The technique comprises: a meta data file, wherein the meta data file includes specifications for one or more macros, each of the macro specifications comprising: a name for a particular macro, wherein the same name may be specified in one or more of the macro specifications; and values for one or more parameters for the particular macro; a Java source code input file, wherein the input file comprises a plurality of lines; a Java source code output file; reading each of the lines of the input file; determining, responsive to the reading, whether the read line is within a scope of a macro reference; copying the read line to the output file when the determining has a negative result; and expanding the read line using the meta data file when the determining has a positive result. The expanding preferably further comprises: parsing each of the lines within the scope of the macro reference; copying each of the parsed lines which does not contain a macro parameter reference to the output file; expanding the parsed line when the parsed line contains one or more of the macro parameter references; and writing the expanded parsed line to the output file. Preferably, the determining has a positive result when an opening macro reference has been encountered but a corresponding closing macro reference has not; and the expanding of the parsed line further comprises: locating one or more matching macro specifications in the meta data file using a reference name from the opening macro reference to match the macro name in the meta data file; and using each of the matching macro specifications to create the expanded parsed line. Using the matching macro specifications to create the expanded parsed line preferably further comprises: retrieving a corresponding one of the parameter values from the matching macro specification using a sequence number from the macro parameter reference; and substituting the retrieved parameter value for the macro parameter reference, wherein the retrieving and the substituting are repeated for each of the one or more macro parameter references in the parsed line.
In yet another aspect, the present invention provides a technique for combining a meta data file and an object-oriented source code input file to create an object-oriented source code output file that will be used to dynamically create objects at compile time in a computing environment. This technique further comprises: creating a meta data file, wherein the meta data file includes specifications for one or more macros, each of the macro specifications comprising: a name for a particular macro, wherein the name may be specified in one or more of the macro specifications; and values for one or more parameters for the particular macro; creating an object-oriented source code input file, wherein the input file comprises a plurality of lines, selected ones of the lines including one or more macro references; and creating an object-oriented source code output file by expanding the macro references in the source code input file using corresponding ones of the macro specifications in the meta data file.
The present invention will now be described with reference to the following drawings, in which like reference numbers denote the same element throughout.